package com.gxa.modules.service.impl;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.R;
import com.gxa.common.vo.ResultVo;
import com.gxa.modules.mapper.CommodityMapper;
import com.gxa.modules.pojo.Commodity;
import com.gxa.modules.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CommodityServiceImpl implements CommodityService{
    @Autowired(required = false)
    private CommodityMapper commodityMapper;
//    @Autowired
//    private RedisTemplate redisTemplate;

    @Override
    public JsonResult queryCommodityMap(Integer page, Integer limit) {

//        redisTemplate.opsForValue().set("key","gxa");

        JsonResult jsonResult = new JsonResult();
        Integer param1 = (page - 1)*limit;
        Integer param2 = limit;
        List<Map> contractMap = commodityMapper.queryCommodityMap(param1,param2);
        int result = commodityMapper.countCommodityMap();
        jsonResult.setCount(result);
        jsonResult.setData(contractMap);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");

        return jsonResult;
    }

    @Override
    public JsonResult queryBillchangeMap(Integer page, Integer limit) {
        JsonResult jsonResult = new JsonResult();
        Integer param1 = (page - 1)*limit;
        Integer param2 = limit;
        List<Map> contractMap = commodityMapper.queryBillchangeMap(param1,param2);
        int result = commodityMapper.countBillchangeMap();
        jsonResult.setCount(result);
        jsonResult.setData(contractMap);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");

        return jsonResult;
    }

    @Override
    public ResultVo searchCommodityByClass(String commodity_class_fst, String commodity_class_sec) {
        ResultVo resultVo = new ResultVo();
            List<Commodity> contractList = commodityMapper.searchCommodityByClass(commodity_class_fst,commodity_class_sec);
        resultVo.setMsg("查询成功");
        resultVo.setCode(200);
        resultVo.setData(contractList);
            return resultVo;
    }
}
